package openai

import (
	"shyxy-model-agent/core/config"
	"shyxy-model-agent/pkg/model"

	"github.com/gofiber/fiber/v2"
)

func ListModelsEndpoint(dbLoader *config.DBLoader, modelLoader *model.ModelLoader) func(ctx *fiber.Ctx) error {

	return func(ctx *fiber.Ctx) error {
		var dataModels []string
		models, err := modelLoader.ListModels()
		if err != nil {
			return err
		}
		if len(models) == 0 {
			return ctx.JSON(fiber.Map{
				"object": "list",
				"data":   []string{},
			})
		}
		for _, m := range models {
			dataModels = append(dataModels, m.ID)
		}
		return ctx.JSON(fiber.Map{
			"object": "list",
			"data":   dataModels,
		})
	}
}
